package com.zone.domain.credit.service.adjust.impl;

import com.zone.domain.acticity.model.entity.ActivityOrderEntity;
import com.zone.domain.acticity.repository.IActivityRepository;
import com.zone.domain.common.factory.FactoryName;
import com.zone.domain.credit.event.UserCreditAdjustEvent;
import com.zone.domain.credit.model.valobj.TradeNameEnum;
import com.zone.domain.credit.service.adjust.IUserCreditAdjustService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: zongzi
 * @description: 兑换抽奖(活动流水单)
 * @date: 2025/3/14
 */
@Slf4j
@Service
public class ActivityOrderRedeemAwardService implements IUserCreditAdjustService, FactoryName {
    @Autowired
    private IActivityRepository activityRepository;


    @Override
    public void adjust(UserCreditAdjustEvent adjustEvent) {
        ActivityOrderEntity activityOrderEntity = activityRepository.queryActivityOrderByOutBusinessNo(adjustEvent.getOutBusinessNo());
        Validate.notNull(activityOrderEntity, "未查询到活动流水单, outBusinessNo：%s", adjustEvent.getOutBusinessNo());

        // 根据活动流水单充值活动账户
        activityRepository.rechargeAccountByOrder(activityOrderEntity);
    }

    @Override
    public String getName() {
        return TradeNameEnum.ACTIVITY_ORDER_REDEEM_AWARD.getCode();
    }
}
